What OS and filesystem is that?
Did you try some other location or USB flash drive?
Do you have some special file/directory permissions?
Do you run some AV software, cloud synchronisation, backup software or something similar which could interfere with filesystem?
Did you try to test it on different computer?
It's just Windows 11.
Location is the same, I showed you that it makes the file in the beginning, and then it doesn't want to rewrite() for overwriting.
Location is nothing special, a folder on my data partition on the big SSD drive that replaced the older HDD.
There is nothing that can possibly interfere with that.
Ok, I'll get it to run on a Windows VM...
There *is* something that interfere with your file, that is the reason I wrote possibilities that I could think of.
It could be something in your program, it could be open in external program, it could be something with OS, with AV, ...
Maybe you could try at the same time (at the beginning of your SaveToFile method) to create/rewrite some other file (try in the same location and also somewhere else), just for test. See if that works or fails.