The problem is with your $replace.
The purpose of this code is to replace the old nick with the new one inside that variable, when someone change their nick.
The problem is that $replace will replace any occurence of what you give to it: let's say the variable's value is "n ni nic nick nick1", now let's say the nickname "n" change is nick to "hello", you're going to do "$replace(n ni nic nick nick1,n,hello)", and here I'm sure you start understanding the problem, $replace will replace all occurences of "n", resulting in "hello helloi helloi helloic helloick helloick1", this is how your variable can be that big.
To fix the problem, you should post how you are setting the variable first (but I assumed each nick is seperated by spaces), if that is true, use $reptok instead of $replace.