Use the correct tense form:When he entered my room I (write) a letter.
When he entered my room I was writing a letter.
One sentence is Past indefinite and the other is Past Continuous tense.