Lock pickle file while writing to ensure consistency