Safer writing of gear registry to disk

Use atomic_write and fsync when writing the gear registry to disk.