Nothing wrong with the script: to prove it, I put together a very simple demo file to demonstrate it in action.

Hope it helps.