Saving files: some work towards first saving to a temporary file and then overwrite the original file (#523) [ci skip].