If in doubt print something to the server console. During development I do a lot of that. I think that as Dave points out it is probably the var statement.
I have a fair bit of LotusScript code that I run as background agent, and that works well,however, I never use them to return information. Write a SSJS code or a Java auction.
The other day I was doing some experimenting on some SSJS code I have been using to open a document in a custom control. I was passing a form name and I had to relate it to a control to open. In my test I got the start time in milliseconds and the time from the before page loads. This process took about 75 milliseconds. I created a viewscope java bean (I do everything from a single XPage so l'm almost always in the same view). Now that same process take 6 milliseconds! Now the 75 milliseconds load time is hardly noticeable but it clearly demonstrate the concept. From LS to SSJS would no doubt be significantly faster, then to Java a further step up.