The Magic Flute is a quest item from The Hag's Assistant quest. It is obtained during the quest, along with a map, by roughing up some Imps to reveal the location of Zeefzorpul. Going to the location indicated by the map and then using the flute will reveal Zeefzorpul.
Since the map leads to a general location, it may take several attempts with the flute to make him appear. After revealing Zeefzorpul, he will snatch the flute and return a recipe he stole, the disappear after boasting of besting a stupid human. The next step of the quest is to then return to Grizelda the Hag.
The Hag's Assistant Quest is a classic quest and so some of the quest items are implied and not seen, or for the items that do appear, such as the magic flute, do not have quest timers that cause them to decay while in a character's backpack. If one wishes to keep the flute, simply quit the quest prior to the step where Zeefzorpul snatches it away.
The magic flute has no other use or purpose outside of the quest except for a curio or decorative item.