I want to output the template that is currently being viewed in my footer

There is this post that never got answered and I wanted to do a similar thing

Something like this in functions.php

So I can see in my footer what template is being rendered.

add_action('wp_footer', 'show_template');

function show_template() {
    global $template;
    echo '<div style="margin: 0; padding: 10px; background-color: #fff; color: #000; position: fixed; bottom: 0; right: 0; z-index: 9999;">Template: ' . basename($template) . '</div>';

But I have been reading that functions.php is not the best place to add things for code organization.

I read that I could make a custom plugin, a MU Plugin or use a service provider. Could someone advise on which would be the best route, and how to go about doing so for said route, I know nothing about setting up either of these options really.