How do you determine that "application can not write the specified file"? You can't find the file or you get an error message? What error?
'log.txt' doesn't include the full path so many things may affect to where its trying to save to.
How early must this app be executed? If it should run when user logins to Windows, simpler way to make app start is placing its shortcut in Start-menus Startup folder. That way you don't need registry things.