writepid(): Correctly check for failure to open pid file for writing