use lock_ex for file write operation