The first thing to remember is that the present perfect tense is actually a present tense like its name says! It's about past events, but it's describing the present situation. For example,
I have lost my wallet - as of right now, my wallet is lost
I had lost my wallet - before some other time in the past, my wallet was lost
Let's use your second example first: I couldn't open the door because I (bring) the wrong key.
"I couldn't open the door" is describing a past event, so whatever tense we use after because should be in the past also (because it had to happen before not being able to open the door).
"...because I have brought the wrong key"? But have brought is the present perfect, and describes a present situation. That doesn't make sense because we're talking about an event that happened in the past.
"...because I brought the wrong key." That's the simple past, which is used to describe events completely in the past. That would be a good choice here.
"...because I had brought the wrong key." That's the past perfect, which is used to describe an event that happened in the past before another event in the past. That would also be a good choice here, because first you brought the wrong key, and then you couldn't open the door.
Now let's look at your first, more complicated, sentence:
When I listen to a song that I have been listening to in the past I usually remember what I have been doing while I have been listening to it before.
When I listen to a song that I have been listening to in the past - have been listening to in the past doesn't sound right. Firstly, "have been listening to" is the present perfect continuous tense, which is used to mean an activity that began in the past but continues until the present (like "I have been living here since 1985"). But you say "in the past", which implies that the listening was entirely in the past. Have listened to is OK because you're talking about how a past event influences the present. So a better way to phrase it would be
When I listen to a song that I have listened to in the past...
...I usually remember what I have been doing... This doesn't work either. Remember, have been doing is a present tense. But you want to talk about something that happened at a specific time in the past while you were doing something else. It would be better to say
...I usually remember what I was doing...
...while I have been listening to it before. Again, this doesn't really make sense, because you were listening and doing something before, in the past, but have been listening is a present tense. A better way to phrase it would be
...while I was listening to it before.