Decades ago, the sociologist Georg Simmel argued that nothing unites a nation, or any group of people for that matter, quite like having a common enemy. Recent research by Mark Landau (professor of psychology, University of Kansas), though not testing unity of groups, does indicate that having enemies provides some psychological benefits.
Specifically, Landau and colleagues argue that people have a basic need for coherence, or for things to make sense. Enemies provide people with this sense of coherence. If we can attribute many of the ills in our lives to our enemies, then we have a stable set of schemas and expectations. We know what to expect, even if something bad happens, and we know who to attribute it to.
Several studies support these ideas. In one study, participants who were lead to think about chaotic hazards were more likely to perceive people with different political beliefs as enemies (view them as more part of a conspiracy).
Interestingly, in another study, people who had just imagined a powerful enemy (Al-Qaeda) actually thought the world was less dangerous and chaotic.
Put differently, this research suggests that people create enemies in order to maintain a stable, coherent, clear view of the world. This is because they can attribute the negatives of the world (which are inevitable) to these enemies.