Move write_pid to after we daemonize. Fixes #180