What do you mean by “does not work?” What do you see on the serial monitor and on you SD card’s file? When you say “The code itself works to display the data in the serial monitor, but it does not works when recording it into the SD card.” do you mean that you can see data on the Serial Port monitor do you mean that if you replace all instances of “sensorsdata” with “Serial” then the data is printed to the serial port monitor, or do you mean that when running the code as is you don’t see any error messages? There are nothing really obvious errors jumping out at me in your code.
Please, in the future, use the “Add Code Snippet” button to post code.
Also, I would always recommend PlatformIO over the Arduino IDE.