Not illegal but there is no value of this affidavit.
When U sell ur car - the new owner is liable to transfer it to his name. If he failed to do so, he have to pay penalty against ownership change for each day - otherwise, he will not be able to sell it. Also he may face problem at check points as the only thing with him to proof that he is the owner of the car is - Expired Transfer Deed (no value).
The previous owner is not responsible for anything happend after the date when car is handed over to new owner - and all this is clearly mentioned in stamp paper signed by both parties and witnesses.
So in ur case - U just need to keep the photo copy of stamp paper and transfer deed.
But the issue is - if something happend, u will also suffer as car is registered against your name. Then U have to provide all the documents/stamps - and witnesses who signed may also be called.
As the buyer is your known person infact friend - then hopefully there will be no such issue.
Issue can be if he sell the car to another person - but as he has dated transfer letter - car must be transfer to his name before selling.