A.D.
next time she points out that someone is better than her, i would appeal a little bit to her competitive side. "well, i guess you'll just have to work at this so you can be just as good as they are! would you like some help?" or maybe give her a goal to work on, like she will get bring home her best test in addition by the end of next week. giving her something to aspire to might motivate her to really give it her best.
also, try an after school activity that can help raise her self esteem, like karate. karate is great for kids who beat up on themselves emotionally and mentally, and can help teach discipline and self control.
talk to her teacher and see what you guys can work on at home with her. see if teacher has any suggestions or concerns of her own.
also, let her see you "fail" at something. to our kids we're awesome and wonderful and dare i say "perfect", and it's a lot to live up to because they want to be just like us. if they see us mess up, and we own up to it and say "well, i guess i'll have to to better next time" or "this really isn't my best work" or "i'm not very good at this, but i'm going to try it again anyway!" it can encourage them greatly to know that the world won't end if they stumble.
in response to your edit: the fact that she performs better when you're around i think really shows that she is afraid to disappoint you or let you down. is it possible that she might be sensitive and sees your encouragement as criticism? i was a sensitive child and took EVERYTHING as a negative if it wasn't outright praise. i have no solution for it, but it might be something for you to think about.
maybe dad should take over homework duties? or sit down and have a talk with her. let her know that if she doesn't do her homework, there will be consequences. school and homework are her job right now and it's very important that she take responsibility and do it in a timely manner. my best friend has a set time for homework for her 6 and 9 year old, and if they don't do their homework during that time, they are not allowed to do something the next day, like watch a movie, read recreationally, or have a friend over. it's very effective as her 9 year old starts moving into the tweener attitude. perhaps that would work for your daughter?
lots of hugs, lots of encouragement, lots of patience, but you already knew that! i think it's great you're so in tune with your daughter's feelings!
good luck!