Factored out create_pidfile routine