I suspect that the problem lies with the exact location of the button. Maybe the script (or rather 'you...'!) is being fooled by which record is active when you click the button. To test that I'd suggest:
- click in the record you want to view. Click the script from the Script Menu and confirm it works the way you expect.
- go back to that record view. Click the button and see if it works. Go back to the original view and see if the active record is absolutely definitely the record that you thought you started on.
Just a thought.