This looks weird to me. The meaning of a Twig function is that it returns some content. If ``debug()`` is outputing the debugging data, there is 2 solutions to respect the Twig semantic:

- make it a Twig tag rather than a Twig function
- use output buffering to return the output