SD Card-Reading data from a "text file" then saving some text to other textfiles

Hi there, i have a problem with regard to reading and writing data from different text files.

I am making an attendance system. Names of the employees will come from individual text files.
e.g. My id tags are “AB1234CD” and “QWERTYUI”

Filename: AB1234CD.TEXT Content: “Juan Dela Cruz”
Filename: QWERTYUI.TEXT Content: “Peter Josh Sam”

My aim is after swiping their ID’s, their names will be displayed to the LCD then their time stamp of their entry will be saved “APPENDED” to the last line of the “log.txt” file.

This are my variables used:

myFile - file object
dataFile - file object

fn - char - contains filename. THe format is 8.3 filename. Filename will come from RF ID tag (trimmed to 8 chars) + “.TXT”
extension
id_buf - this will hold the text (employee’s name) that will be read. Text file only contains maximum of 15 characters.
whatever read will be displayed to the LCD
beep() - just a function for beeping

    myFile = SD.open(fn,FILE_READ);
    if (myFile)
    {
      while(myFile.available())
      {    
        myFile.read(id_buf, 15); 
        lcd.setCursor(0,3);
        lcd.print("Name:");
        lcd.setCursor(5,3);
        lcd.print(id_buf);
        beep(70);
        beep(70);
      }  
      myFile.close();
    }


//Code for writing another text


  
      File dataFile = SD.open("log.txt",FILE_WRITE);

      // if the file is available, write to it:
      if (dataFile) {
        dataFile.println("Sample Contain.......");
        dataFile.close();
      }

My problem is, if i run it without this code

     File dataFile = SD.open("log.txt",FILE_WRITE);

      // if the file is available, write to it:
      if (dataFile) {
        dataFile.println("Sample time stamps....");
        dataFile.close();
      }

everything works fine. Data is read from a text file and displayed into an LCD.

But after putting this portion of that code. It never worked. plus, the about code also doesn’t work anymore…

These codes are inside the “void loop()”

I am not really sure if the problem is by using the SD.open() into different file open modes. “FILE_WRITE,FILE_READ or simply putting nothing or whatsoever”.

Try to run only this portion in setup()

File dataFile = SD.open("log.txt",FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
  dataFile.println("Sample time stamps....");
  dataFile.close();
}
else 
{
  Serial.println("Getting Error")
}

then check the file in sd card for data if the result seems fine next time put some delay before the above portion in loop e.g.

.
.
.
delay(100);
File dataFile = SD.open("log.txt",FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
  dataFile.println("Sample time stamps....");
  dataFile.close();
}
else 
{
  Serial.println("Getting Error")
}