Adding Filter | Page Title | Template | Why the_title affecting on menu?

There are a lot of things that can be improved in the code, like the use of global variables, but Im guessing you are learning so I’ll answer your question first.

You can try this technique to alter the title only in the page, keeping the menu intact.

Try this tutorial

Basically

Go to Appearance -> Menus and your menu item. Here you will see the changed page title. In order to keep the old menu name, open this menu and type it under the navigation label and click Save

Also consider reading this for the correct use of the global keyboard