When I am at the karaoke with my friends, I often sing with them and realize, when I sing alone, I can sing the song perfectly but when I sing with someone that is of higher pitch/lower pitch, I tend to automatically switch to a higher/lower pitch, depending on the person I am singing with, which affects me. Are there any methods I can use in order for me to not fall into their pitch? Thank you in advance.
This is a very common problem, particularly when singing harmonies. It's easy to slip onto the other person's part!
If you want to study methodically, get a hymn book and practice singing the alto or bass part while a friend sings the tune.
Instruments -- piano, tanpura etc -- are more kind and tolerant than fellow humans. They will put up with any amount of fumbling patiently!
And nowadays there exists a "universal instrument" -- computer (or cellphone). Just make sure it has a half decent speaker.
And spend your time -- alone with this patient harmonizing friend!
PS Can share some musescore exercises if you like