The previous code could potentially truncate and change ownership of a file that's a symlink to an unintended target file (requires the attacker to be able to create the symlink in the directory the PID file is located, which generally requires root privileges).