US stock market closes flat, indices post weekly gains