Why do most open source projects use licenses instead of simply releasing the code into the public domain?
The answer is actually pretty complicated.
Public Domain isn't a thing everywhere
This may be surprising, but in many jurisdictions, the concept of the public domain doesn't exist. Even for jurisdictions where it does exist, it varies. Some jurisdictions enforce the right to attribution, even for works in the public domain. Some governments might even charge people to use works in the public domain, most notably Norway. Simply put, there's no one-size-fits-all definition for the public domain.
Open Source != public domain
For the sake of argument, let's just assume that the public domain is similar to Canada or the US.
Open Source simply doesn't cut it for the public domain. Many licenses include disclaimers of warranty and liability, others with the attribution clauses, others that grant patent/trademark rights, and then there's also the entire concept of copyleft. Simply put, open source is much more complex than the public domain.
Open Source is also a "third party" thing, in that its definition and control is not in the governments hands. Anybody can grow open source, but the definition of the public domain falls to elected parliamentary officials. With the control of open source in the hands of the people, it is also able to evolve as time passes.
You can dedicate code to the public domain, and be open source. Licenses such as CC0 dedicate code to the public domain. But for people who wish to bring additional open source restrictions, such as copyleft, it wouldn't work.
If open source was public domain, then open source wouldn't exist.
This is just touching the brink of it. There are also many other factors, but the two above are probably the biggest ones.
instead of simply releasing the code into the public domain
In addition to Zizouz212's great answer let me add that there is no way to "simply release code in the public domain". When you put some code in a public repo on GitHub for instance, you do not give many rights to the people who find the code because copyright applies. To put some code in the public domain, you also have to use licenses (such as CC0).
Aside from the legal convenience of very explicitly listing out the rights...
Many open source developers wouldn't mind getting acknowledged for their work, and very few people and corporations mind giving them credit. Everybody likes a nice, permissive license -- they don't really have downsides. I particularly like Apache 2.0, as it includes an explicit patent license!