simplified write_pid_to_file() by using fopen() instead of open()