As far as I know, there is a fixed phrase/idiom for saying what are you doing here? but I have forgotten it.
It is a very formal and polite way of saying that.
What are you doing here? can sound impolite and even rude.
Does anyone know that phrase/idiom?
Edit after Msfolly's answer:
Sorry for not giving a context.
The context I had in mind was like: Suppose you saw your friend near your home and you want to know what he is doing there, so you would ask what are you doing here? (the meaning is literal). But there was a polite alternative to what are you doing here?...