Move file write out of mutex too