read from and write to text file