You have to move the "local AddOnList = {}" outside the do...end block or the rest of your code won't be able to see it.
Code:
local AddOnList = {}
do
for i = 1, GetNumAddOns() do
local folderName, title = GetAddOnInfo(i)
if not exempt[folderName] then
table.insert(AddOnList, {name = title})
end
end
table.sort(AddOnList, function(a, b) -- sort alphabetically
return a.name > b.name
end)
end