write pid to a file if requested