Change locking approach from flock to fopen(…, 'x') + rename.