The dollar finishes its best month since July as war in the Middle East upends energy markets, buffets economic forecasts, and sends investors rushing to the world’s primary reserve currency.