Because science is an inherently social activity
Our popular imagery of science often focuses on the lone genius pursuing his or her vision through late nights, often over the opposition or indifference of an uncaring world. This is not at all how good science is done (except for the late night part).
The world is complex, and even the smartest of us are dumb-asses by comparison. Our knowledge is always fragmentary and incomplete, we have blind-spots and obsessions, we try to cram our observations into our preferred theoretical frameworks, even when they really don’t fit. This is why the majority of what gets published is wrong, or at least, incomplete.
We need other people to tell us that we are on the wrong track, because that is the only way to get back on the right track. Ideally, one’s lab-mates will do this, but science is full of strong and sometimes charismatic personalities who, intentionally or not, tend to suppress dissent in their immediate circle.
Publishing papers allows others – our rivals and competitors in particular – to expose our weaknesses, preconceptions and blind spots for what they are. They allow us to fail in public, and thus enable us – collectively – to succeed.
It is not a coincidence that science and the scientific method (as formulated by Francis Bacon) began to emerge soon after the development of an advanced communication technology (printing). Knowledge is pretty much coextensive with communication, and cannot exist independently of it.