I'm not convinced that it would increase costs.
I'll bet that there's a lot of reinvented code in science. If every project released their code, new projects would start reusing code from current projects. In some cases, that sharing and reuse would reduce costs.
I don't personally have the hubris to think I can code up a method better than the people who invented it in the first place. That aside, it's just so wasteful.
So instead of spending time on novel work we were doing, I spent a month implementing a half-baked version of something other people had done.
Reimplementing from scratch then comparing with the original gives an opportunity to find such bugs.
I doubt one would rewrite the OS, compiler or runtime libraries because they couldn't be trusted; though all these can also have bugs.
I'm reminded of ESR's paraphrasing of Linus' Law regarding eyeball count and bug depth. Ten haphazard proprietary implementations are not more reliable than one battle-tested open implementation.
While I can imagine any number of reasons people might post facto not wish to release code, if it were developed from the start with the intention of releasing it, I think we'd all benefit.
Inevitably, the cost of doing so would increase the cost of the research, but I believe it would be worth it.