When you start to write a script on the script edit add:
{
}
this way when you execute the contents of the {} variables inside them gets distroyed by maya and you can do what ever you like with it.
When you type directly in the script edit all the variable become globals and you cannot redeclair them anymore.
-a