Arduino SD Card - Error while opening file. (Creating a unique file)

Hello,

I am facing problems with the code below.
Since I developing code for a bigger project, the code is split into functions.

The program creates a new unique file every time I reboot my Arduino, very helpful when it's a data logger.


What's the problem?
It successfully creates a new unique file. But when opening that file crashes(myFile = 0)
check main.ino

Psuedo Code

  //Create a file with new name
    if (!loadSDFile()) {
    Serial.println("Failed to create file");
    while(1);
    }
     else {
    Serial.println("File name created!");
    }

  myFile = SD.open("DLOG.txt", FILE_WRITE);

  if (myFile) { 
    
    "worked"

   } else {
   
    "didn't work"

  }

What have I tried, so far?
I tried writing the code in a separate environment. The weird thing is works! Have no idea how and why?
Check - SD_MODULE.ino

Equipment
Arduino Nano
MicroSD Card

Please help.
If there's any other suggestion for my code. Please do tell.

Check the two files in the attachment.

main.ino (15.4 KB)

SD_MODULE.ino (3.62 KB)