The discount giant is spending billions to reinvent and seeing it pay dividends.