US stock market closes higher despite early losses