Can a 3rd party js script write cookies?

Yes, third party scripts can write cookies, and they will appear to belong to the domain of the page itself.

You can see this if you examine the cookies of any site using Google Analytics - the content comes from a third party (Google) but the _utm prefix cookies will be on the hosting site's domain.

To write third-party cookies (i.e. where the cookie is on the domain of the third party) requires that the cookies be sent in the headers of a download from that third party, and not written by JS code.