changed script to read and write to file