What could cause uneven fuel levels in a Cessna 172?
Consulting your handy POH (or one for a 172N that I Googled up) you'll find the fuel system diagram looks like the one below (click to enlarge - most high-wing gravity-fed fuel systems are similar).


So there are a number of ways you could wind up with uneven fuel burn with this plumbing.
The most common ones are:


(Uncoordinated) Turns
If you're flying lots of left-hand traffic patterns (or you're making lots of left turns for some other reason) that means your left wing is frequently lower, and gravity favors pulling fuel from the right tank. (Note that it doesn't have to be a turn - prolonged slips can also cause uneven fuel flow.)
If I had to take a guess, I'd say this is probably your culprit. Were you making a lot of left turns?
Pressure
The fuel vent tube on the left tank faces into the wind - this pressurizes the left tank first (and the right tank through the breather tube connecting the two) - it's a little extra encouragement for fuel to leave the tanks and flow into the engine. In some aircraft this leads to the left tank draining faster (because it's at a slightly higher air pressure than the right tank) - this can become particularly pronounced if the breather tube between the two tanks is blocked.

Various blockages
A partial blockage in either of the tank fuel lines, the fuel selector valve, the vent, or the breather line between the two tanks could theoretically cause uneven fuel burn (the vent/breather blockages being a special case of "pressure" from (2) above).
Pilot Error
It's possible to mis-position the fuel selector in such a way that you're getting adequate fuel flow to run the engine, but one tank is more restricted than the other.
This is unlikely if the aircraft is properly maintained (the fuel selector should have nice, identifiable detents that it clicks into, letting you know it's in position).


For more detail on causes for uneven fuel burn (and tips for troubleshooting it with your mechanic) check out Cessna Pilot's Association Technote 003.



Is uneven fuel burn dangerous? Maybe.
It's certainly something you should be aware of (part of why you want your fuel gauges to be at least somewhat accurate is so you can tell if your fuel burn is uneven in flight and correct it by switching to the fuller tank briefly).  

Uneven fuel burn can be an annoyance (a 5 gallon difference is about 30lbs - potentially enough to notice on the controls), but it can also be a safety hazard: If allowed to go uncorrected you could theoretically get yourself into a situation where the right fuel tank is empty, and in a steep enough left turn you may not have enough pressure from gravity to get fuel from the left tank into the engine.  

In an extreme case your right tank may be empty and your left tank may be so low as to unport the fuel pickup tube in a turn, potentially leading to attitude-induced fuel starvation ("The noisy part of the plane gets quiet until you level the wings").