Getting data from files and writing to other file