As posted above, I don't know why a medication such as Xanax would be prescribed for pain; there are plenty of medications that are specifically designed to reduce or otherwise minimize pain. Xanax (or its generic equivalent) is not; it is meant to relax the patient.
As also posted above, when medications are prescribed and used correctly, they are quite beneficial.
However, as a function of marketplace competition, I do think that pharmaceutical companies provide physicians with incentives to prescribe their product instead of another company's product.