There is a bug that does not allow you to create new files on an SD card. This can be fixed by using a Linux system command to create an empty file.
// check if the file exists, if it does not,
// then create an empty file with that name.
if(!SD.exists("test.txt")){
Serial.println("test.txt does not exist, creating.");
system("touch /media/mmcblk0p1/test.txt");
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);