As far as I know and read, there is nothing that allows to write in an unfamiliar language directly, but there are some workarounds.
True Polymorph
If you know the race this is your best bet: you can polymorph* into a creature of that race and write in the language of your new form
The target's game statistics, including mental ability scores, are
replaced by the statistics of the new form. It retains its alignment
and personality.
This is the most direct way of writing in another language that I can think of.
*- Crawford twitted a comment on True Polymorph and languages. Also, there is this question about language.
If transformed by the true polymorph spell, the creature would speak what the new form speaks.
Wish your way out
For a more permanent solution but as risky as a moody DM can be, the spell Wish can make you "learn" a new language (with all its implications). For a "risk-free" way wish it to be temporal.
Get external help
I was tempted of not including this one since it is obvious, but there is a particular spell that can help you in a situation where everyone is your enemy: Dominate Person. Fetch yourself a creature with the language that you desire, apply the spell and watch your new assistant do all the work for you. The downside is that it wont be able to write you a book since the duration is up to 8 hours spending an 8th level spell slot.
While the target is charmed, you have a telepathic link with it as
long as the two of you are on the same plane of existence. You can use
this telepathic link to issue commands to the creature while you are
conscious (no action required), which it does its best to obey.
Also, spells like Conjure Celestial are alternatives if the particular language are within any race that can be summoned and can write.