SD Card, Read, Write, Overwrite

I’ve been trying for several days now to simply write/overwrite to an SD card. I’d like just a single integer to be repeatedly overwritten. I’ve wrestled with the code, but now it’s not even writing at all! Can someone please check this code and see where I’m going wrong. The goal (in this example) is to iterate through an id and overwrite the file at each loop, then read out the characters.

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

const int CS = 12; //chip select
uint32_t id = 577652; //this number will need to be long
String filename = "TESTCASE.txt";

void setup()
{
  Serial.begin(9600);
  if (!SD.begin(CS))
  {
    Serial.println("Card not loaded");
  }
  else
  {
    Serial.println("Card ready");
  }
  File datafile = SD.open(filename, FILE_WRITE);
  Serial.print("File found?"); Serial.println(datafile);
  if (datafile)
  {
    datafile.println(id);
    datafile.close();
    Serial.print(id);
    Serial.println(" saved to SD card ");
  }
  else
  {
    Serial.println("Couldn't save the number");
  }
}
void loop()
{
  Serial.println("Entering loop()");
  id++;
  Serial.println(id);
  //File datafile = SD.open(filename, O_RDWR | O_TRUNC); //alternative way of overwriting didn't seem to work for me)
  SD.remove(filename); //delete old file so it can be overwritten (removal doesn't seem to be working)
  File datafile = SD.open(filename, FILE_WRITE);
  if (datafile)
  {
    datafile.print(id);
    Serial.print("Number overwritten is ");
    Serial.println(id);
  }
  datafile.close();

  delay(1000);

  ///Now read off the card to see what is written.
  Serial.println("+++++++++");
  Serial.println("Reading from SD Card");
  File readfile = SD.open(filename, FILE_READ);
  while (readfile.available()) {
    char c = readfile.read();
    Serial.print(c);
  }
  readfile.close();
  Serial.println("\nSD Card read complete");
  Serial.println("========");
}

Using this SD library

http://forum.arduino.cc/index.php?topic=560685 again ?

Yes, the previous post was asking more about resources on where to find documentation on the function. This one is asking for help troubleshooting code. Sorry for the double post, I just ran across different problems