For a quick-and-dirty fix you could use a global
declaration when defining the original variable:
global WordsWithChanges
But that is considered very bad practice and I would not recommend it.
To really fix your problem: This is occurring because if you create a variable in a scope, it is only available in that scope. Therefore a variable can be locally but not globally defined. As I said in my comment, this indicates you should probably rethink the program logic.