When you loaded your template file, you already passed the `'template_redirect'` hook, which is too late (See: [Plugin/Action API Reference](http://codex.wordpress.org/Plugin_API/Action_Reference)). You need to set the `add_action` call in your functions.php file, which is loaded before the `after_setup_theme` hook - which is the first available hook for themes.