Writes a JSON file using an atomic write operation to prevent corruption from interrupted writes. Writes to a temporary file first, then renames.
Details
The function writes to a .tmp suffix file first, then uses file.rename()
to atomically move it to the target path. If the rename fails, a
bayesim_checkpoint_error is thrown.