Mario,
Are you running Windows 7 with UAC enabled? If so, the code you sent tries to write to the root directory, but usually UAC prevents writing to this area without admin privileges.
Try to change the path of your file to a temporary directory that everyone has full control (I usually create a C:\temp to do my File I/O tests) and see if it works fine.
Hope this helps,
Rafael