Employer sent me legal notice as I not served notice period ,also security deposit cheque I closed.

I received an offer from company "B" and, due to this offer, I had to leave my current organization ("A") after fully serving my notice period. However, on the joining day at company "B," they asked me to provide an undated cheque for two months of salary as a guarantee in case I did not serve the notice period in the future. They also had me sign a contract for the same. Since I had a running loan at the time, I had no option but to comply, so I provided the cheque to the company. After two months and 15 days, I submitted my resignation to company "B" due to my mother's heart disease and the unsuitable work environment. I contacted the CEO of the company and requested an early release, to which they initially agreed but later denied. I returned the company laptop and stopped working for them. At that time, I also sent an email to the HR department to inform them that cheque has been canceled canceled. Despite this, they presented the cheque at the bank for encashment, which was returned due to insufficient funds since I had already canceled it. Subsequently, the company sent me a legal notice through their legal advisor, demanding the amount along with 18% interest and a fee of 11,000 for the legal notice. Is it legal for the company to demand this amount from me? Additionally, they have not paid my last month's salary.