Arduino and SD card problem

I have Arduino Mega with the SD (not microSD - not sure if that important) card module. Here is a sketch I use:

#include <SPI.h>
#include <SD.h>
File myFile;
File meFile;
String file_name;
String file_name2;
int filenameNumber = 1;
int fileData = 0;

void createlogFile() {
  String ext = ".txt";
  String ext2 = ".tx";
  while (1) {
    file_name = filenameNumber + ext;
    file_name2 = filenameNumber + ext2;
    if (SD.exists(file_name) == false) {
      break;
    } else {
      filenameNumber++;
    }
  }
  myFile = SD.open(file_name, FILE_WRITE);
  myFile.close();

  if (SD.exists(file_name)) {
    Serial.print("1. Log file: ");
    Serial.print(file_name);
    Serial.println(" created.");
  }
  delay(50);
  meFile = SD.open(file_name2, FILE_WRITE);
  meFile.close();

  if (SD.exists(file_name2)) {
    Serial.print("1. Log file: ");
    Serial.print(file_name2);
    Serial.println(" created.");
  }
}

void updatelogFile() {
   delay(50);
  if (SD.exists(file_name)) {
    myFile = SD.open(file_name, FILE_WRITE);
    myFile.print("# ");
    myFile.println(fileData);
    myFile.close();
    Serial.print("2. Log file: ");
    Serial.print(file_name);
    Serial.println(" updated.");
  } else {
    Serial.print("2. File ");
    Serial.print(file_name);
    Serial.println(" doesn't exist.");
  }
  delay(50);
  if (SD.exists(file_name2)) {
    meFile = SD.open(file_name2, FILE_WRITE);
    meFile.print("# ");
    meFile.println(fileData);
    meFile.close();
    Serial.print("2. Log file: ");
    Serial.print(file_name2);
    Serial.println(" updated.");
  } else {
    Serial.print("2. File ");
    Serial.print(file_name2);
    Serial.println(" doesn't exist.");
  }
}

void setup() {
  Serial.begin(115200);
  Serial.print(F("Initializing SD card..."));
  while (!SD.begin(53)) {
    Serial.println(F("initialization failed!"));
  }
  Serial.println(F("initialization done."));
createlogFile();
}

void loop() {
updatelogFile();
  delay(1000);
  fileData++;
}

It copiles without the errors. But on the console I can see something like that (randomly doesn’t exist the first file, both, the second one):

Initializing SD card...initialization done.
1. Log file: 2.txt created.
1. Log file: 2.tx created.
2. Log file: 2.txt updated.
2. Log file: 2.tx updated.
2. File 2.txt doesn't exist.
2. File 2.tx doesn't exist.
2. File 2.txt doesn't exist.

Strange things - the files are on the card:

Volume in drive E has no label.
 Volume Serial Number is 6CE0-F3F8

 Directory of E:\

01/01/2000  01:00               654 1.TXT
01/01/2000  01:00                 8 1.TX
01/01/2000  01:00                 3 2.TXT
01/01/2000  01:00                 0 2.TX
23/01/2020  11:22    <DIR>          libraries
23/01/2020  11:22    <DIR>          hardware
26/01/2020  13:26                 0 log2.txt
               5 File(s)            665 bytes
               2 Dir(s)   7,897,579,520 bytes free

And finally even stranger thing - the errors happen when I compile the sketch on my Win 7 laptop and on Mac OS X computer. When it is compiled on another Win 7 computer it seems to be working without errors (haven’t noticed any after running for about 15-20 minutes). On all machines is a fresh installation of Arduino 1.8.10. Libs in user’s directories are the same (copied from the working Win 7 computer).

Is that me doing something wrong?

Regards.

What else I noticed - sometimes there is no "file doesn't exist" messge but when I open the files one contains only very few lines while the other one - hundreds... I also tried another SD module - nothing changed still doesn't work as expected.