SD card write issues

I just got my SD module all wired up following this tutorial: Micro SD card Tutorial - using SD cards with an Arduino!

I tried the CardInfo sketch and it seemed I had wired everything up correctly. But when I tried using this code to write to a file:

#include <SD.h>
File myFile;
void setup()
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");
  // 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 ="test.txt", FILE_WRITE);
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
	// close the file:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
void loop()
	// nothing happens after setup

It creates the TEST.txt, but its empty :frowning:

I had my LCD connected through the serial TX RX pins 0 and 1 and thought maybe that was the trouble. So I disconnected those two pins and tried again, same issue :frowning:

Also if you can’t use the serial pins for more than one thing at a time, then why was my LCD connected to those pins but I was still getting output from the serial monitor?