Write the terms and frequency to a file