What a drug company that pays a nominal fee to license that drug does is all the testing and data collection required to get it onto the market, something the university labs have no hope of doing.
Most drugs fail because either they're only as effective as sugar pills or some hidden danger pops up and the study is ended quickly.
This is where the cost comes in and why they're granted a 17 year patent on that drug. Once the patent expires, the theory goes that companies that manufacture generics will lower the costs.
Also, competitors do some R&D, coming up with "me-too" drugs that are slightly different chemically and can qualify for their own patents. Much of the time, these drugs are better than the originals. Sometimes (Vioxx, I'm looking at you) they kill people when they start to be widely used and the company gets sued. That also piles on the costs.
Finally, there's the pharmacy markup, which is enormous. It also makes sense as every pharmacy has to stock hundreds of medications and all those medications have expiration dates.
So it's not the stuff that goes into a drug or the test tube development that costs, it's the effort it takes to make sure it's effective and safe and get it to you. That's what you're paying for, especially when a drug is on patent.