Here, 'had been written' in past perfect tense is correct because it is used to indicate a completed action of the past that happened before another event took place.
'Was writing' in past continuous is incorrect because it
is used to indicate a completed action of the past that happened before another
event took place.
'Wrote' in simple past is incorrect because it indicates
an action that has already been completed.
'Written' is incorrect because the usage of 'that' in the sentence makes it grammatically incorrect.