This is software engineering, so we can expect the team leader to be rational and someone you can reason with using logic and arguments.
Lastly, the interviewer asked for my current salary and expected salary. This question caught me off guard as it is purely HR related question
This does not strike me as odd, when I was in IT managing developers, we would talk about this during interviews. It is not strictly a HR matter. Also this depends on the company size, if it is a small company then maybe there is no HR, or HR is just one person. Don't presume you know the inner workings of a company just because you walked in. Maybe the IT manager is the HR lady's boyfriend. This was the case in a company I worked in. So, obviously, they would both talk together! No issue about that.
Yesterday while talking to the friend who referred me for that job, I came to know that the team lead might reject me due to salary.
OK, you have inside help. Good.
I and interviewer have almost same years of experience. He is interviewing candidates for first time in his career.
Yeah, my first interviews from the other side of the desk were kinda "fly off by the seat of the pants, no idea what I'm doing." Factor this in.
Should I email HR regarding this situation
NOOOOOOOOOOOOOOOOOOOOOOOO
The first thing you do to your next manager, while not being hired yet, is go over their head and talk to their boss or HR...
Just think about the image you are presenting here: "If there is any problem in the future, I will not talk about it with you dear manager, instead I will go directly to HR."
Nope, nope, nope.
If you write an email, then put everyone who should read it in the address line. Both your future manager and HR. Simple.
If so, what should be the wording of the email because I also don't want to bad mouth the interviewer?
I suggest emailing your next boss, tell them something like that:
The salary I asked for was my default estimate. While walking on the way home, I realized I can just walk to your offices and not use my car, so I will revise my own price down (sorry, I have no idea how to properly word this in English, but you will know).
Also emphasize the reason why you want to work with them is not only convenience: mention you talked with some team member while there, or how much the project interests you. Try to strike a balance between brown-nosing and genuinely interested.
Of course your insider friend will tell you how much you should ask, so you will ask a wee bit less.
I quickly found out that working with amazing people on interesting projects mattered more than a +/- 10% difference on the paycheck.
50% difference, maybe not.