Extract file saving code into saveStringAsFile()