Prevent race conditions when writing to results file.