My suspicion is that running the find request is refreshing the window to your default tab rather than the chosen tab. If this script is only be used when switching to a specific tab, you could include a step before the exit to go a layout object which appears only on that target tab (after the Find has executed) so you'll land on the right tab at the end of the script.
Thanks Stephen, that does it! I just added the "Go to object" step, using my "$category" variable defined in the first line of the script, as the target. My script now works perfectly.
It's often a matter of getting all the right pieces and in the right order.