Saving filenames in txt

Hello. I would like to save root files names in txt file. Could you suggest how to do it?

  // List files in root directory.
  if (!root.open("/", O_READ)) {
    sd.errorHalt("open root failed");
  }
  while (n < nMax && file.openNext(&root, O_READ)) {
    if (!file.isSubDir() && !file.isHidden()) {
      file.printName(&Serial);
      Serial.println();
    }
    file.close();
  }

I tried to create brand new file, open it and “print” like this, but witout any result.

file.printName(&myNewFile);

I tried to create brand new file, open it and "print" like this, but witout any result.

Why would you want the file to contain the address of the file name in memory?