Why does fs.writeFile not save file?

Try not using the fs library if possible, this would not work on mobile:
https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md#nodejs-and-electron-api

There are methods on Plugin#.app.vault for that: https://marcus.se.net/obsidian-plugin-docs/api/classes/Vault

You can see what errors are produced in the console:

To check for errors, first open the developer tools by pressing Ctrl-Shift-I on Windows/Linux or Cmd-Opt-I on macOS, and then go to the “Console” tab.