As an extension of
てくれる, which expresses that something was done for the speaker, or someone within their immediate circle,
てくれてありがとう thanks someone for that action.
-
いつもゴキブリを捕(つか)まえてくれてありがとう。
Thank you for always catching the cockroaches.
-
ケーキを買(か)って来(き)てくれてありがとう!
Thank you for buying the cake for me!
This expression is usually reserved for actions that clearly benefit the speaker. It would not sound natural when thanking someone for something that they are expected to do as part of their job, or due to simple etiquette.
-
弁当(べんとう)を袋(ふくろ)に入(い)れてくれてありがとう。
Thank you for putting my bento in a bag! (Slightly unnatural Japanese, if just plainly thanking someone for doing their job)