You must be sure that this variable is available in every tempate.
it's available in PageLayout and its overrides, but it's available in the other templates? i don't know about it but try to verify it. it can perhaps help you.
The $module_result variable is of course also available in the templates you include from pagelayout.
What you have to do in other templates depens on what your really WANT to do. Do you really need to use this code in all the templates or only in pagelayout?
For example if you want to get the current node id in nodeview you can use:
$node.node_id
On the other hand in the template that overrides user/login you cannot get the current node id since there's no node you are viewing there.