I created a plugin for a niche markup language recently. I asked them if I could use their logo for it on GH, they said yes, I did and added a note to the licence file explaining that their unregistered trademark was used with permission.

It's not hard to do the right thing, either upfront or once you realize you'd done the wrong thing.

On another note, I was once contacted through Apple's infringement service, that the app I wrote, was infringing on someone else's.

The app started with the first four letters of their app name ("Ambi").

they were probably going after any app that started with those four letters, so they would rank higher in searches. Since they used Apple's service, they could probably have had my app taken down, even though there was no way that their claim had any merit.

In that case, I was planning on changing the app's name, anyway (it wasn't a very good name), but I could see this kind of thing being a huge PItA.

Hell Apple has given me problems for infringing on my own trademark- accidentally registered an app under the wrong developer account and tried to just delete and recreate under the correct one, took multiple rounds of review and having to file my own trademark complaint for them to allow me to use the name again. Great way to get stuck in App Store Hell

I have not done it, but I think there’s a way to transfer published apps.

I have, however, made the same mistake as you. I work under three different organizations, and can miss which one I have selected (also, Apple is constantly randomly changing the initial one I am logged into). In that case, it was just at the start of development, and I could easily change the bundle ID.

I have transferred published apps before, and was hoping to avoid bringing Apple into the loop to transfer my own app to myself or deal with the absolutely ancient interfaces still in place for that process since this app hadn't been published. Lesson learned the hard way, jump through the Apple hoops or get the stick.