Your deposit has to be held by the independent deposit scheme in Scotland so your landlord can’t keep it and then refuse to pay you it back. Make sure they pass it over within 30 days.
If they don’t then just don’t pay your last months rent, ask them to use the invoice to cover and then settle any invoices for damages as and when they arrive.