How to remove same words from set?

I want to find the number of unique words. I have a code that does that but not quite what I want. It is only processing one line at a time and not looking at all of the lines at the same time to find the unique words, thus giving me the incorrect number of unique words.

So, I was thinking whether or not if there was a way to remove the same word that has already been inserted into the set. I am not sure how to go about it or if there's another way.