In situations where there are two or more people for whom the same personal pronoun is appropriate (usually two people of the same gender) and the linguistic relationship is complex, as in your example (your first use of "he" refers to Martin, your second to Mr Clayton and the third to Martin again) the best solution is to use either the names or descriptions of the protagonists rather than attempt to disambiguate the pronouns. To use descriptions you could call Mr Clayton "the manager" and Martin "our hero".
Using names would give:
Sometimes Martin saw Mr Clayton while Mr Clayton was looking over the account books Martin had written before.
Using the suggested descriptions would give:
Sometimes Martin saw Mr Clayton while the manager was looking over the account books our hero had written before.
In this case I think the descriptions work better but in other contexts repeating the names is better. Of course you can mix the solutions as well giving things like
Sometimes Martin saw Mr. Clayton while the manager was looking over the account books Martin had written before.
This is often the best solution of all.