Factorize saving a file.