All habits serve a purpose: we want to make the habits that cost us in the long term ("bad" habits) be less desirable in the short term too.
SOURCES:
Clear, James. Atomic Habits: Tiny Changes, Remarkable Results : An Easy & Proven Way to Build Good Habits & Break Bad Ones. New York, New York, Avery, an imprint of Penguin Random House, 2018.
https://jamesclear.com/three-steps-habit-change