in reply to unable to open existing file after trying to open a non-existing one

For one thing, I think you're confusing Perl's open and C's open. Perl's open returns 1 if successful, whereas C's open() returns 0.

Update: While the above statement is true, the OP is not confused. I'm the one who is confused about what OP's code was doing. Apologies.