1 more update, I wrote a similar function and tested it on Windows XP and Windows 10 Enterprise and on XP 32bit SP2 there is no problem, everything works correctly, but on Windows 10 enterprise the opening and writing to a file is not working. I used the exact same portable codeblocks.
Sounds like a possible Anti-virus software issue.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson