Calculating cosine similarity and printing result to output file