A person writes down defamatory statements, and they accidentally are communicated to someone else. Is that considered defamation?
Defamation is the act of one party making untrue factual1 statements about another party and communicating them to a third party. Publishing - for defamation law simply means communicating the information to a 3rd person(s) and the defamer must be involved in the communication, either actively or by negligently allowing it to happen.
If I say nasty and untrue things about my brother to my brother that is not defamation. If I say them to my wife, then that is defamation 2.
If I write the same things in an email to my brother or record them in my private diary that is not defamation. If I copy someone else into that email or allow my diary to be read by someone else then that is defamation2.
1. I know "untrue factual" sounds like an oxymoron but the idea is they have to be untrue statements about things that are objectively true or false ("X is a serial killer" X is either objectively a serial killer or they are not) not things which are not objectively true or false ("X is not a nice person" there is no objective standard by which X's "niceness" can be measured - this is an opinion).
2 The damages that flow from a defamation suit depend on how badly the person's reputation was damaged. In cases where the information has only limited distribution (like me to my wife) the representational damage is insignificantly small. There have been cases pursued and won (usually in the context of acrimonious family relationships) for such limited distribution, however, damages awards are usually similarly limited ($1 and no costs order being typical).