In the way it was used, the person used it to portray either confusion or anger/disappointment for being at a certain place. "What the heck was I doing here?" or "What the hell was I doing here?" could have also been used.
It's a vulgar term; unfortunately it is very common in English. Since it is slang, it can have many meanings; but it generally means "nonsense" and it can also be used when someone exaggerates the facts or lies. Those who want to prove a point, get attention, and show they may know more about a topic also use it a lot - on YouTube look up videos of John Legere, the T-Mobile CEO who's famous for using the term. ...but in the sentence you provided it has different meaning; as most slang words can.