The Messenger of Allah ﷺ said, "From the moment one of you leaves his house heading to his mosque, one foot records a good deed and the other erases a bad deed."
حدثنا هاشم عن ابن أبي ذئب عن الأسود بن العلاء الثقفي عن أبي سلمة
أن رسول الله ﷺ قال من حين يخرج أحدكم من بيته إلى مسجده فرجل تكتب حسنة والأخرى تمحو سيئة
Its chain of transmission is sahih.Imam Ahmad also narrated from Abdullah bin Umar with the wording, "Whoever goes to a congregational masjid, one step erases a sin and one step records a good deed for him, going and returning." The chain of this narration is hasan.Tabarani narrated it, and Ibn Hibban in his Sahih, and Nasai narrated it in the Book of Prayer from Amr bin Ali.