First thing you need to do is check the error value on return from both WriteProfileString() and GetFileVersion() and handle any errors.

This will immediately point you in the right direction - probably path failure or permissions problems.