Only open the pid file if we're going to use it

This moves opening the pid file from the options handling code to right before it's actually going to be used. This prevents a cppcheck warning about a resource leak.