Since the thought came to you before your friend spoke, then options are (including elucidatory additional text):
I just thought the same thing, just a moment before you spoke
I had just thought the same thing, several moments before you spoke, (and then you did speak)
although I might prefer that to be:
I had just been thinking the same thing...
But the meaning changes a little if you ditch the "just":
I thought the same thing,...
I had thought the same thing,...
Both of those are setting up for something like "...but then I changed my mind"
Finally, again because the thought came before the friend, the following doesn't work for me at all:
I have just thought the same thing.
Although, harking back to one of the earlier forms, I'd be OK with:
I have just been thinking the same thing...
Contrast that with the earlier form in question:
I had just been thinking the same thing...
The difference is that the "had" version implies that some significant event then occurred (e.g. the friend arriving or speaking) prior to the present moment, whereas the "have" suggests that while thinking started prior to the present moment, it has continued into the present, and no intervening event is implied.
Sigh -- overall, though, it's bloomin' complicated. Can I suggest you just go out and buy a new toothbrush. They're not that expensive. ;-)