Do I need to leave the country to file for a provisional unlawful presence waiver?

You don’t need to leave the country in order to apply for the provisional unlawful presence waiver. You apply for it when you’re in the United States. Only if the waiver is approved, then you’ll have to finish counsel of processing abroad, which does require you to leave the U.S.