Count words in a text file and print result both in console and into a file