So there are problems with peer-review, but it's not quite as bad as you are making it out to be here.
Talking about the process of how a submission becomes published will help explain.
First, the author submits an article to a journal for consideration. At this stage, the article is prepared for blind review, so there is no identifying information in the manuscript.
Second, the editor of the journal will decide whether the submission is worth being refereed or not. If not, then the paper is "desk rejected". Many journals get several hundred submissions a year, and there simply aren't enough people to adequately referee them all. So the editor has to make some call about which papers are worth spending the valuable resources necessary to bring the article up to publication quality on.
If editor thinks the article maybe has a shot of getting published, he or she will send the article to referees for comment. Usually the paper goes to between one and three referees.
Different journals can be ranked in terms of who knows whom in this process.
A single blind journal will be one where the referees don't know the authors of the papers they are refereeing.
A double blind journal will be one where neither the referees nor the authors know each others identities.
A triple blind journal will be one in which neither the referees, nor the authors, nor even the editors know the identities of the authors and referees. (These kind of journals require editorial assistants who handle the emails and so forth to preserve the integrity of the process)
Now even triple blind journals are susceptible to failures of the review process. It can just so happen that you get asked to review a friend's paper, or a paper you happen to have heard at a conference. Ideally, a referee in such a position should recuse themselves, but my sense is that that doesn't happen often, just because it's often really difficult to find qualified referees who are willing to volunteer their time, so recusing oneself might be equivalent to getting the paper automatically rejected for lack of qualified referees.
There are problems with actual implementation to be sure, but overall I think the process at triple-blind reviewed journals is sound.