What is the purpose of a departure procedure?
A major advantage is standardization. An aircraft can be given a departure procedure, and assuming everything goes to plan, everyone involved will be on the same page as to what is going to happen. When air traffic control instructs an aircraft to fly a departure procedure, a large volume of information (e.g. climb to this altitude, turn this way, turn that way, etc...) can be communicated just by giving the name of the procedure. This is far more convenient and predictable for both the crew and controllers than giving every instruction individually. This allows controllers to focus on preventing conflicts and dealing with abnormal situations rather than issuing routine instructions, and it reduces the risk those instructions may be miscommunicated or misunderstood. 

The procedure itself will have been developed by specialists based on all sorts of criteria, among them:


Obstacle clearance. This can be anything from the huge mountain range near the airport to buildings to towers to anything else. The procedure can be designed with a required minimum rate of climb, and pilots can ensure they are able to meet that requirement to climb over any obstacles. Obstacles might also be virtual, such as restricted areas for military purposes.
Noise abatement. Communities in the vicinity of airports often have noise complaints. Departure procedures can be designed to direct aircraft away from noise sensitive areas. 
Traffic flow. Near a busy airport, large numbers of aircraft are maneuvering at low altitudes. Standardizing departure and arrival flows along certain corridors allows air traffic control to deal with aircraft moving in predictable ways and avoids potential conflict between different aircraft. Departure procedures help ensure separation between arriving and departing aircraft.
Regional traffic flows. In congested airspace where several busy airports are located in close proximity, procedures can be developed to ensure that traffic to and from each airport are kept separated. A good example is the busy airspace around New York City, where complicated departure and arrival procedures are used to separate traffic into the region's airports.
Winds. Different runways may be used depending on wind conditions. There may be different departure procedures available for different runway configurations and/or universal departure procedures that have different instructions depending on the runway used.
Navigational aids. While modern RNAV procedures are now available, traditional departure procedures guide aircraft from the runway through routes navigable through NAVAIDS like VORs and NDBs onto established airways.


Of course, an aircraft flying a departure procedure can always be given instructions to deviate from that procedure if it becomes necessary, such as for other traffic. If conditions permit, it's also possible for a controller to give a "shortcut" by circumventing part of the procedure, perhaps by turning early toward the next waypoint on the flight's filed route.