Costco Wholesale Corp. posted higher-than-expected profit as moderating prices fueled consumer spending and store traffic climbed.