use standard flock instead of lockfile gem; write json safely