We don't really KNOW that this is the case, because our deepest galaxy surveys still have only looked at the nearest galaxies out to about 1 billion light years. This is only about 1 percent of the current spatial volume of our visible universe. However, astronomers that have been mapping very distant quasars out to 1- 5 billion light years or more, have found evidence that these very luminous galaxies are not clustered, and seem to be randomly and 'smoothly' distributed in space, so the cosmological ASSUMPTION that the universe is ON AVERAGE rather smooth, seems to be borne out when the most distant objects are studied. Locally, the universe has lots of structure in clusters of galaxies, voids and other 'artifacts'. Finally, the cosmic background radiation itself says that by at least 300,000 years after the Big Bang, the expansion of the universe was very smooth to 1 part in 100,000 or so.
As for the universe being 'flat', this is an expectation based on the Inflationary Big Bang model, and not one that seems to be borne out by the current observational evidence. The evidence shows that for a Hubble Constant near 65 kilometers/sec/megaparsecs, the ages of globular cluster stars agree with the expansion age of the universe only for an actual density near 25 percent of its critical density. The universe seems to be far from a 'flat' cosmology implied by a density = 100 percent of critical for its current expansion speed.