my code is running but nothing is written to file

in my project i use a keypad to select different members and through xbee i generate different values and transfer from one room to other , in the second room i use xbee to receive the numbers from key pad, and i can recieve the numbers and the task assigned for numbers is occuring, but no text is printed to the file in memory card, i use rtc ds1307 for date and time and memory card module and an xbee, please help me to solve this problem ,

#include <SPI.h>
#include<SD.h>

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
File file;
int CS_PIN=10;
   //Rx,Tx

void setup() 
{
Serial.begin(9600);

delay(1000);
initializeSD();
  delay(1000); 

  Wire.begin();
  rtc.begin();

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(2015,6,2,9,31,0));
    
      
  delay(1000);
 
 createFile("stack.txt"); 
}
void loop() 
{
 int x;

DateTime now = rtc.now();
  delay(1000);
Serial.println(file);

  while (Serial.available())
    {
    x=Serial.read();
     Serial.println(x);
     delay(1000);
    
  
  switch(x)
      {
        case 49:
        {
Serial.println(file);
  // if the file is available, write to it:
  if (file) 
  {
    delay(2000);
    file.println("  Mrs.K.HARIPRIYA   EMBEDED SYSTEMS  ");
    
   
    
    // print to the serial port too:
    Serial.println("  Mrs.K.HARIPRIYA   EMBEDED SYSTEMS  ");
  }
  break;
      }
        case 50:
        {
Serial.println(file);
  // if the file is available, write to it:
  if (file) {
     delay(2000);
    file.println(" Mrs.N.Parijatham  CONTROL SYSTEMS");
    
   
    
    // print to the serial port too:
    Serial.println(" Mrs.N.Parijatham  CONTROL SYSTEMS");

  }
  break;
      }
        case 51:
        {
Serial.println(file);
  // if the file is available, write to it:
  if (file)
  {
     delay(2000);
    file.println("  Mr.K.Praveen      DSP  ");
    
    // print to the serial port too:
    Serial.println("  Mr.K.Praveen      DSP  ");
  }
  break;
      }
        case 52:
        {
Serial.println(file);
  // if the file is available, write to it:
  if (file)
  {
     delay(2000);
    file.println("  Mr.TSRCH Murthy   DC  ");
    
    
    // print to the serial port too:
    Serial.println("  Mr.TSRCH Murthy   DC  ");
  }
  break;
      }
        case 53:
        {
Serial.println(file);
  // if the file is available, write to it:
  if (file) 
  {
     delay(2000);
     file.println("  Mr.BALA KRISHNA   OOPS  ");

    
    // print to the serial port too:
    Serial.println("  Mr.BALA KRISHNA   OOPS  ");
  }
  break;
      }
        case 73:
        {
           

Serial.println(file);
  // if the file is available, write to it:
  if (file) 
  { 
    delay(2000); 
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
     delay(2000);
     file.print(now.year(), DEC);
     file.print('/');
     file.print(now.month(), DEC);
     file.print('/');
     file.print(now.day(), DEC);
     file.print(' ');
     file.print(now.hour(), DEC);
     file.print(':');
     file.print(now.minute(), DEC);
     file.print(':');
     file.print(now.second(), DEC);
     file.println();
   
    // print to the serial port too:

  }
  break;
        }
    case 69:
        {
          Serial.println(file);
  // if the file is available, write to it:
  if (file) { delay(2000);
   
     file.print(now.hour(), DEC);
     file.print(':');
     file.print(now.minute(), DEC);
     file.print(':');
     file.print(now.second(), DEC);
     file.println();
   
    // print to the serial port too:



  }
  break;
        }
    
         
}
}}
      
      
          

void initializeSD()
{
  Serial.println("Initializing SD card...");
  pinMode(CS_PIN, OUTPUT);

  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
}

int createFile(char filename[])
{
  file = SD.open(filename, FILE_WRITE);

  if (file)
  {
    Serial.println("File created successfully.");
    return 1;
  } else
  {
    Serial.println("Error while creating file.");
    return 0;
  }
}

i can observe in the serial window but nothing is printed to SD card , wen i see sd card only an empty text file is created

If you use CTRL-T in the IDE the code will auto indent and will look better readable

what is this line supposed to do?

Serial.println(file);

The data is not physically written to the card until there is a file.close() statement.

You need to manage your open and close file statements better. I would recommend starting each case with a
file = SD.open("stack.txt", FILE_WRITE); and ending each case with a file.close().

case 49:
        {
          file = SD.open("stack.txt", FILE_WRITE);
          Serial.println(file);
          // if the file is available, write to it:
          if (file)
          {
            delay(2000);
            file.println("  Mrs.K.HARIPRIYA   EMBEDED SYSTEMS  ");



            // print to the serial port too:
            Serial.println("  Mrs.K.HARIPRIYA   EMBEDED SYSTEMS  ");
          }
          file.close();
          break;
        }

Thank you , the words are printed to SD card.