Because often they DIDN'T fail the first time. It's just that when the next batch of devs decided they needed something, they didn't bother learning from the previous generation, and instead re-did every mistake of the past 30 years, to finally "invent" the already-working approach that had been there for decades.
One example that springs to mind is GUI code. We've gone through 3 cycles of that so far (including the original).
Another is programming languages.