Novak Djokovic had to dig deep to avoid early US Open exit