It’s not entirely clear to me what you’re trying to do but…
Our STM32 application has some configuration settings that we keep in internal flash so they persist between resets.
Our settings are held in binary form, i.e. just write the struct to flash. Actually, it’s a bit complicated because we keep to copies and hash them and stuff like that! We thought about using NVStore but decided not to in the end.
The location of the settings structure is hardcoded. They are at the top of flash so the flash size is reduced a bit in the linker script.
In production, we write the default settings to the flash using the JTAG programmer, just like programming the code. We’ve got a little PC app that writes the settings in binary to a binary file on the PC.
You say you want to ‘write a file’. If by that you mean you want to write a file using a file system and you want to just copy a file from your PC to the device, then that’s something different altogether.