Synchronize writing to file