Sd card interface not working properly

I have a code for SD card interface from the internet and I realised that the SD card is not working properly. So when I run the code The file gets created and the numbers are sometimes there sometime not there etc. I have only seen one number printed to file at max

#include <SPI.h>
#include <Seeed_FS.h>
#include "SD/Seeed_SD.h"

File myFile;

void setup() {
  // put your setup code here, to run once:
  while (!Serial) {
   Serial.print("Initializing SD card...");
   if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) {
    Serial.println("initialization failed!");
    while (1);
  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);


void loop() {
  // put your main code here, to run repeatedly:

  for (int i=0; i<256; i++){
    myFile ="test2.txt", FILE_WRITE);
    myFile.println("Write num");


Seems that there should be no myFile.close() often when we want to open the file again for writing. It’s okay to write no close() function.