At what age should an adult be able to differentiate basic homonyms in writing? :)
Quite seriously, spelling (homonyms or not) is not a subject in which everyone eventually gets A+. Consider textbooks like that of Coffin et al. (2002) on how to make sure undergraduate university students understand things like this:

Compared with spoken language, writing is artificial and abstract, more than you might think if you haven't tried to teach it or study language acquisition. Writing homonyms correctly depends on a few different skills that a child gradually acquires; this list is not exhaustive:
- Understanding that spoken words have graphical representations
- Understanding that spoken words are made up of discrete sounds
- Understanding how to decompose a word into its sounds
- Understanding that the graphical representations are actually linked to sounds, not words
- Compare sight-reading words and sounding out words. How good is the child at reading a new word? If the first half is like a word they know, do they just spit out that word?
- The granularity differs from language to language (letters corresponding to sounds, syllables, whole words)
- Learning all the names of the letters and the correspondences between sounds and letters
- Understanding that the relationship between letters and sounds is one-to-many in both directions
- Well-known foible of English, less chaotic in languages with spelling reform
- Starts early in elementary school with lessons on "long A" and "short A", "hard A" and "soft A", and other metaphors to describe relationships between letters and sounds
- Understanding that even the relationship between written and spoken words is one-to-many in both directions
- How can one word have multiple spellings? Take e.g. color (US) vs. colour (UK)
First, consider these steps of abstraction and arbitrary rules that every kid has to learn in order to learn to read and write. They start out not even being able to respond to prompts like: "Take the first sound out of plump. What word do you get?" because they don't have the phonological awareness to decompose a word.
Then, pause on that last step with me. My "color/colour" example is meant to get you to remark how trivial it is that a word can have multiple spellings. I mean, it's still the same word, right? Who cares if it has a "u" or not!
Now consider that this actually describes the case of homonyms. The child knows the word /ðɛə(ɹ)/. They've used it fluently in many contexts since they were not much more than a year old. Now they learn that it has three different spellings: "there", "their", and "they're".
To make matters worse, the rules for when to use each one are not child's play, no pun intended. It's not a tidy geographical thing like adding "u" if you're in the UK. It suddenly requires one more step that most adults never master:
- Understanding the syntactic structure of the language
- Understanding what a demonstrative adverb is
- Understanding what a possessive determiner is
- Understanding what a contraction is
Those points of grammar are not easy. Even if you just do it based on things like apostrophes, you run into hurdles. An apostrophe marks the possessive in John's, but the lack of an apostrophe marks the possessive in its, where the apostrophe instead marks a contraction (it's). Confusing? It's a small fragment of the system teachers have to get straight in a kid's head by the end of Grade 12. Gradually, most educated people do get a sense of when to use each homonym, but probably could still not articulate the rules.
It's not going to happen smoothly for everyone. Graduation doesn't require getting an A+ in spelling in every grade. And misspelling rarely hinders understanding, even if it's annoying to proofreaders. As such, there are few serious incentives to master the system. People here could give you an ideal target (maybe between Grade 5 and 8?) but it depends on far too many factors to be useful.
Reference: Coffin, C., Curry, M. J., Goodman, S., Hewings, A. Lillis, T. M., & Swann, J. (2002). Teaching academic writing: A toolkit for higher education (pp. 21-32). New York, NY: Routledge.