It's impossible to control what other people do, even if you want to try. You may be best friends with someone who drinks too much or uses drugs on occasion, but on the whole, as long as those actions don't impact you, you don't see the harm.
Unfortunately, your friend's behaviors have impacted you. You were pulled over for a traffic stop, but the officer noticed an unusual smell coming from your vehicle. It was marijuana your friend had left in the vehicle. With reason to suspect you had drugs in the vehicle, the officer searched it and discovered a baggie. Now, you're in trouble for something you didn't even know was in your vehicle.
The good news is that claiming that drugs belong to someone else is a good way to defend yourself in court. For example, you could state that you had just been with friends in the last few days and that you were unaware that the drugs were in your vehicle. You might suggest that you were out of state where it was legal and that you were unaware that any was left in your vehicle by passengers. There are many defenses you can use, depending on the facts of your case specifically.
Our website has more information on what you should do if you're pulled over from an unrelated offense and are charged with a drug crime. There may be several good ways to create a defense to help you protect yourself and prevent serious penalties from being lodged against you. With help, you can fight back.