U.S. stocks erased earlier gains and closed lower as tech shares weighed down the market.