That will depend on which environment you are working on. For example, if you are working from shell, you can use the following command to write a value in a text file:
echo "string_value" >> file.txt
If you are working from the Arduino IDE, you can use the methods of the SD library. I recommend you to check the ReadWrite example or the Datalogger example. Both are located in the Arduino IDE under File>Examples>SD. You need a SD card to run the examples.