ないうちに focuses more on unfavorable results

知らないうちに、家の前にあるラーメン屋が潰れていた。 Before I knew it, the ramen shop in front of my house went out of business. (which is not nice)

に is more general

食べる前に、手を洗わなくてはいけない。 Before you eat, you need to wash your hands.

bunpro - ない内に