I believe you're looking for Her Evil Twin, book 6 of the Poison Apple series.

This review/reenactment has a pretty good summary:
Anna (Lin-Z Wright) gets a note from a popular girl, Jassamyn (Allie Puglisi), in class. It says to meet them in the old girls bathroom. Anna tells Dory (Christina Vo) about the note. Dory says it could be a trick. Anna gets mad at her and goes to the bathroom anyway. Anna saw Jassamyn and her friends (Jordan Fernandes). They tell her to look in the mirror so she can "face the spirits." She sees someone in the mirror and faints. ~ When Anna awoke, Dory is there telling what happened. Anna says she actually saw something but Dory doesn't believe her. ~ At science class, they are supposed to dissect frogs. Anna feels sick and the teacher (Jordan Fernandes) tells her to go to the nurse. When she was walking to the nurse, she meets this girl, Emma (Katherine Vo). Emma convinces her to ditch school and they do. They do a lot of bad things. Anna gets caught later and is grounded and not allowed to go to any school events. They say that there is no Emma Diablo that goes to the school but Anna says she does because Emma said so. ~ Anna thinks and find out that Emma is really her imaginary friend when she was younger. ~ Anna meets Emma again and Emma plans to hurt Dory at the dance. ~ Anna goes and warns Dory but she doesn't believe. ~ Anna sneaks of to the dance to help save Dory. Anna thought she saw Dory going to the bathroom, but it turned out to be Emma who tries to pull Anna in the mirror. Dory comes and rescue Anna. Emma disappears into the mirror and Anna & Dory become friends again and they have a blast at the dance. (DJ is Jordan Fernandes)
Found by Googling book "imaginary friend" mirror dory