I agree with Robert and Grace, you can't change it without changing the meaning or at least the feeling of the utterance. Usually if you were to use "had" in that way, it would be to contrast another part of the story, or because you no longer know them. For example, if you added "had" before "had dinner" in the first sentence, it would have the exact same effect. It looks a little strange but this pattern often happens.
"Last night, I had had dinner with two friends but I stopped for a snack on the way home anyway."
This happens because you're telling a story where, in the story itself, you had eaten dinner in the past. The story is in the past (last night on the way home, after dinner) but dinner took place in the past, at the time of the story.
"to have dinner" and "to have known [a person]" seem similar but they aren't the same. "I had dinner" means "I ate dinner" but "I had known both of them for a long time" means "I knew both of them for a long time but stopped knowing them sometime after the start of the story and before now". The story will usually involve why you no longer know them, especially in this case, since it was just last night. (What happened between last night and now that you no longer know them?).
"I remember, when I was ten, that rainy day at the park with my best friend Jenny, we had known each other since we were five." (as an adult, you may no longer know each other)
"My sister and I had been very close until she moved away for school."
"My sister and I have been very close all our lives."
"We had known each other a long time but he still ignored me in the hallways." (part of a story about the past)
"We have known each other a long time but he still ignores me in the hallways." (a description of a daily situation)
"My friend had given me his best advice and I tried to follow it, but I wasn't able to succeed." (story in the past)
"My friend has given me his best advice and I'm trying to follow it." (ongoing story)