Close PID file before deleting it

Addresses #135

The agent was first opening the pidfile to check the pid and then, if it
found it to be stale trying to delete it while it was still open.  This
works fine under Linux/Unix, but fails under Windows.