Write pid files to the appropriate location