Corrected bug with file opening

If file didn't exist, script would fail.

Removed useless if block, changed file open to use w+ isntead of r+