There's nothing wrong with the script. Make a new file and paste it in there instead. It's likely that your script is never triggered due to something else triggering before it in the same file.
Go to File > New and paste the script in there instead and it's likely to work.