SD card issues

Hi,

I am trying to use the SD card (Sandisk 8GB) for my code. I am using Arduino Mega.

The problem is for the first two times the loop is executed and the text file is written in SD card. But it stops abruptly after that and it shows SD card initialization failure.

Serial.begin(9600);
mySerial.begin(9600);
pinMode(pinCS, OUTPUT);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
if (SD.begin(53))
{
Serial.println("PP SD card is ready to use.");
} else
{
Serial.println("FF SD card initialization failed");
return;
}

void sdcard()
{
char fileName[16]; // SDcard uses 8.3 names so 16 bytes is enough NOte room for the '\0' char is needed!
unsigned int nr = 1;
while (nr != 0)
{
sprintf(fileName, "file_%03d.txt", nr);
if (SD.exists(fileName) == false)
break;
Serial.print(fileName);
Serial.println(" exists.");
nr++;
}
Serial.print(fileName);
Serial.println( " created.");
myFile = SD.open(fileName, FILE_WRITE);
myFile.println("testing 1, 2, 3.");
myFile.close();
Serial.print("SD card done");
}

void loop()
{
}

What may be the problem?. Can somebody help me.

Thanks in advance.