Updated code to save data as txt files