Most likely, you've loaded more than one script with a matching on text event.
Also note that there's a superfluous "$chan;" identifier in your code.