Right; but the pharmaceutical industry goes out of its way to avoid competition. They won't develop drugs if there is too much competition.
I understand that someone needs to pay for R&D. Unfortunately, the US government already pays for most drug R&D, but the patents get assigned to the company doing the development in all but a few rare cases.
The US gov't does not pay for most drug R&D. It pays for most of the basic science, that often leads to drug candidates, but the industry shoulder nearly 100% of the cost of getting a drug to market.
The combined, private R&D budget for biotech is ~$70B (not including VC funding). Total NIH funding (much of which is not drug focused) is ~$30B.
They go out of their way by lobbying, which is to say they go out of the free market scope in order to avoid competition. So you are wrong in blaming the free market for this.
And when you say 'They won't develop drugs if there is too much competition' that only means that those existing companies won't do it - and as soon as they leave the market because they don't want to compete, several entrepreneurs will step in and fill the void because they're not afraid of competing.
I understand that someone needs to pay for R&D. Unfortunately, the US government already pays for most drug R&D, but the patents get assigned to the company doing the development in all but a few rare cases.