write correct pid to file