Need help writing data to text file on SD card.

The filename is probably causing the trouble. You must use filenames with an 8.3 format with the SD library.
"tempsensor.txt" is 10.3

Pete