If you are attempting to use the code you provided as a macro within the webpart, it will not work because URLHelper is not available as a macro. So yes, it does make a difference where you are using the code. Not all methods/functions are available as macros. It is a method that can be accessed in code behind but has not been exposed as a macro.
You might look into using what I suggested, create a custom macro, or looking into using document aliases with parameters.