Drugstore chain Rite Aid filed for bankruptcy as it faces a mounting debt pile, slowing sales and lawsuits alleging it oversupplied painkillers.