Open the file you'll be writing the data to using a File object and FileSystem.open(). With the modifier FILE_APPEND, you can write information to the end of the file. If the file doesn't already exist, it will be created. In this case, you'll be creating and writing to a file at the root directory of the SD card named "datalog.txt".
From linino cxonsole type:
touch /mnt/sd/datalog.txt
to confirm directory exist.