Writing a will is not just for those who know their death is near. Everyone is recommended to do it at the earliest opportunity and avoid postponing it.
The Holy Quran says, “Bequest is prescribed for you when death approaches one of you, if he leaves behind wealth for parents and near relatives, according to usage, a duty (incumbent) upon those who guard (against evil).” (Verse 180 of Surah Al-Baqarah)
Although writing a will is Mustahab (recommended), the Quran uses the phrase Kutiba Alaykum (it is prescribed for you) and that is a phrase also used for fasting in Verse 183 of Surah Al-Baqarah: “O you who believe! fasting is prescribed for you.”
Writing a will is so important that the Holy Prophet (PBUH) said: Anyone who dies while he has written a will, it is as if he is a martyr and anyone who dies without having left a will, it is as if he has died in the era of Jahiliyah (before the advent of Islam).