Please forgive me for not writing to you. – This is an understood answer. However semantically, it is not quite a smooth sentence. Let’s say you haven’t been in touch with your oversea friend for a long time and you received a letter from him, you may use the above statement and he will understand what you mean. Consider the following variations of the same sentence.
Please accept my apology for not having been able to write to you. (followed by explanation or excuse)
Please accept my apology for not being able to write to you. (ditto)