A detail from the Fermat-prime-test This question comes from a review of an older study of properties of the "fermat-primetest", but where I did not get aware of the following detail.
With a small spreadsheet-like program I can show the following type of spreadsheet:

We see as index of the columns the number $N$ to be tested, and as index of the rows the base $b$ which should provide the residue $b^{N-1} \pmod N$.
The test with base $b=2$ is much successful: if $N$ is prime, then the residue is $1$.
Just to show the well known problem: there are the Fermat-pseudoprimes, where the residue to base $2$ is as well $1$, but is not prime, see $N=341$. It is also well known that we can repeat the test using base $b=3$ and find that $N$ is composite, because the residue is not $1$.
This is all common knowledge, and I repeat this here only to introduce another question where I do not even have an idea, how to approach this.
We see in prime $N$, that the whole column is $1$ (except the cells where $b \equiv 0 \pmod N$), but moreover we see columns, where the residues have further obvious patterns like $b^{N-1} \equiv b^e \pmod N $ with $e=1$ ($N=346$),$e=2$ ($N=339$),$e=3$ ($N=340$) and so on.
I've tried now to understand the properties of numbers $N$, which have a sequence of residues according to $e=1$ or more explicite $b^{N-1} \equiv b^1 \pmod N$ (the primes $N$ may be interpreted as having residues with $e=0$ or $b^{N-1} \equiv b^0 \pmod N$). Basic pattern-detection with $N$ upto $1024$ didn't reveal something suggestive so far. Perhaps worth to notice: for $N=3^m$ we have $e=3^{m-1}-1$ and for $N=5^m$ we have $e=5^{m-1}-1$ and similar patterns.
So my question is:

Is there some knowledge about the structure of $N$ where the residues follow $b^1 \pmod N$?

P.S. I had made that observation some years ago, and had put a sequence of the $e$ depending on $N$ in the OEIS-database but had then no clue at all how to analyze this
P.S.2 According to the hints in comments below, I've seen in OEIS that the occuring sequences (having $e=2$, $e=3$ and so on) are sometimes found with keyword "Knödel-numbers". But this is not always correct; while my sequences give $b^{N-1} \equiv b^e \pmod N$ where all $b \lt N $ must satisfy the equivalence, the according sequences of Knödel-numbers test only that $b$ where $\gcd(b,N)=1$, so my sequences are in principle subsequences of the Knödel-sequences, and, in reverse, elements of a Knödel-sequence of order $k$ may occur in my sequences with exponent $e$ with $e \ne k-1$.
For instance, with $e=3$ mysequence begins with $4,    8, 12,     20, 24, 28,$ while the $4$-Knödel-sequence begins with $    6, 8, 12, 16, 20, 24, 28,$. The $6$ in the $4$-Knödel-sequence occurs with $e=1$ in my sequences, and the $16$ in $4$-Knödel occurs with $e=7$ in my sequences. A singular sequence in OEIS, where this matches perfectly as well in the description, is for instance OEIS A216090

Well, $346$ seems to be a member of a family of numbers of form $2p$. If $N=2p$, where $p$ is an odd prime, then $a^{n-1} = a^{2p-1} \equiv a \pmod{p}$ and obviously $a^{n-1} \equiv a \pmod{2}$, so $a^{n-1} \equiv a \pmod N$. By the same calculation, $N=2C$ where $C$ is a Carmichael number also works.
In the general case, any such $N$ should be square-free (otherwise if $p^2 \mid N$ taking $a$ divisible by $p$ would always give $a^{n-1}$ divisible by $p^2$). Moreover, in an analogous way to the property of Carmichael numbers, for any prime divisor $p$ of $N$ we should have $p-1 \mid N-2$ (this is just writing down Fermat's little theorem). But that means if $N$ has any odd prime divisor, then $p-1$ is even, so $N$ has to be even too. So we can write $N=2M$, with $M$ being odd square-free number.
Now our first guess would probably be that $M$ is either a prime or a Carmichael number, but this is probably not true – the condition for $M$ is somewhat weaker. I would assume that we can find some additional examples, but it seems you have a lot of data on the topic, so you can search for such examples yourself. Probably they will appear much less often than primes, but I'd guess a bit more often than Carmichael numbers.
