Thanks everyone, I have it resolved already. This is what $avatar is defined:
$avatar = $user->getAvatar();
Reality is, well, the method User::getAvatar() already returns an image url enclosed in html image tag. What I've been doing was to add a duplicate image tag on it, which resulted in a weird glitch that I had no idea how to fix for the last two days. Guess I was just being way too careless, lol.