add function to write txt file