Added functionality to write to text file