You're putting your code in the wrong place. Right now you've got it in the part that creates the aura icons when you first log in -- at that point, you'll never have a target, so your (nonexistent) target will never be an enemy, so you'll always be setting the size to 24. Instead, you need to put your code somewhere that will be checked over and over during gameplay to catch target changes.
Fortunately, the Auras/Buffs/Debuffs element supports several callbacks that make this easy. I'd suggest something like this:
Code:
function b:PreSetPosition()
local size = UnitIsEnemy("player", self.__owner.unit) and 50 or 24
if size == self.size then return end -- no need to continue
self.size = size -- set the new size
self:SetSize(size*b.num/2+b.spacing*(b.num/2-1), size) -- resize the container
return 1 -- to force oUF to reposition all the icons
end
You can put that where you have your current code, and oUF will automatically call it each time it updates the icons.