Catch error in atomic_move when creating temporary file

Fixes #8480