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


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");
     else {
    Serial.println("File name created!");

  myFile ="DLOG.txt", FILE_WRITE);

  if (myFile) { 

   } 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

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)