Function to count words in a file